package cn.zhfeat.utils;

import java.io.InputStream;
import java.util.Properties;

/**
 * 
 * @Title PropertyUtil.java
 * @Description
 * @author wschenyongyin
 * @date 2018年1月19日
 * @version 1.0
 */
public class PropertyUtil {

	/**
	 * 初始化Properties实例
	 * 
	 * @param propertyName
	 * @throws Exception
	 */
	

	/**
	 * 读取数据
	 * 
	 * @param propertyName
	 * @param key
	 * @return
	 */
	public static String getValueByKey(String propertyName, String key) {
		String result = "";
		try {
			Properties prop = new Properties();
			InputStream inputstream = null;
			ClassLoader cl = PropertyUtil.class.getClassLoader();
			System.out.println(cl);
			if (cl != null) {
				inputstream = cl.getResourceAsStream(propertyName);
			} else {
				inputstream = ClassLoader
						.getSystemResourceAsStream(propertyName);
			}

			if (inputstream == null) {
				throw new Exception("inputstream " + propertyName
						+ " open null");
			}
			prop.load(inputstream);
			inputstream.close();
			inputstream = null;
			result = prop.getProperty(key);
			return result;
		} catch (Exception e) {
			e.printStackTrace();
			return "";
		}
	}
}
